package org.lzfto.flink.demo.common.table;

public class PhysicalCustomJdbcTable extends PhysicalBasicTable {

	// custom-jdbc的额外属性
	private String driverClass;
	private String idColCode;
	
	public String getDriverClass() {
		return driverClass;
	}

	public void setDriverClass(String driverClass) {
		this.driverClass = driverClass;
	}

	public String getIdColCode() {
		return idColCode;
	}

	public void setIdColCode(String idColCode) {
		this.idColCode = idColCode;
	}


	@Override
	public String build() throws Exception {
		if (this.getConnector()==null) {
			throw new Exception("请先设置连接器connector属性");
		}
		//标准SQL;
		String result = """
				with(
				  'connector'='%s',
				  'url' = '%s',
				  'table-name' = '%s',
				  'username' = '%s',
				  'password' = '%s'
				""".formatted(
						this.getConnector(),
						this.getUrl(),
						this.getTableName(),
						this.getUserName(),
						this.getPassword()
						);
		
		result+=","+"""
				'idColCode'='%s',
				'driver-class'='%s'
				""".formatted(idColCode,driverClass==null?"":driverClass);
		result+="\n )";
		return result;
	}

}
